<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <title>生成订单</title>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css"/>
    <style>
        .layui-form{width: 80%;margin: 0 auto;}
        .layui-input-block{width: 60%;}
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="example" id="editForm">
    <div class="layui-row" style="margin-top: 20px;">
        <div class="layui-col-md6" >

            <div class="layui-form-item">
                <label class="layui-form-label">客户编号</label>
                <div class="layui-input-block">
                    <input type="text" id="cusId" name="cusId" lay-verify="required" placeholder="请输入客户编号" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">订单编号</label>
                <div class="layui-input-block">
                    <input type="text" id="orderNum" name="orderNum" lay-verify="required" autocomplete="off"
                           placeholder="请输入订单编号" class="layui-input btn2" >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">下单时间</label>
                <div class="layui-input-block">
                    <input type="date" id="orderDate" name="orderDate" lay-verify="required"
                           placeholder="请输入下单时间" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input type="text" id="address" name="address" lay-verify="required" placeholder="请输入地址" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">金额</label>
                <div class="layui-input-block">
                    <input type="text" id="money" name="money" lay-verify="required" placeholder="请输入金额" autocomplete="off" class="layui-input">
                </div>
            </div>

            <!--<div class="layui-form-item">
                <label class="layui-form-label">创建时间</label>
                <div class="layui-input-block">
                    <input type="date" id="createPeople" name="createPeople" lay-verify="required"
                    placeholder="请输入创建时间" autocomplete="off" class="layui-input">
                </div>
            </div>-->
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;margin-top: 30px;">
        <div class="layui-input-block" style="width: 80%;margin: 0 auto;text-align: center;">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="putIn">提交</button>
            <!--<button type="submit" class="layui-btn" lay-submit="" lay-filter="update">保存修改</button>-->
        </div>
        <!--        把id输入框设为隐藏-->
        <div class="layui-form-item" hidden>
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="hidden" id="id" name="id" lay-verify="title" autocomplete="off" placeholder="请输入id" class="layui-input">
            </div>
        </div>
    </div>
</form>

<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="../../js/jquery3.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/area.js" type="text/javascript"></script>
<script src="../../js/select.js" type="text/javascript"></script>
<script>
    $(function() {
        $(".btn2").on('click', function() {
            // var uuid = UUID.randomUUID().toString().replace("-","");

            var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
            var maxPos = $chars.length;
            var pwd = '';
            for (i = 0; i < 8; i++) {
                //0~8的整数
                pwd +=  $chars.charAt(Math.floor(Math.random() * (maxPos + 1)));
            }

            pwd =  "2020" + pwd;
            console.log(pwd);
            $('#orderNum').val(pwd);
            return pwd;
        })

    });

/*    function createTime(v){
        var date=new Date(v);
        var y=date.getFullYear();
        var m=date.getMonth();
        m=m<10?'0'+m:m;
        var d=date.getDate();
        d=d<10?'0'+d:d;
        var h=date.getHours();
        h=h<10?'0'+h:h;
        var min=date.getMinutes();
        min=min<10?'0'+min:min;
        var sec=date.getSeconds();
        sec=sec<10?'0'+sec:sec;
        var str=y+"-"+m+"-"+d+" "+h+":"+min+":"+sec;
        return str;
    }*/

    layui.use(['form'], function(){
        var form = layui.form;
        //判断是增加还是修改
       /* var myUrl = "";
        if($('#id').val() == ""){
            myUrl = "http://localhost:8080/crm/customerOrder/save";
        }else {
            myUrl = "http://localhost:8080/crm/customerOrder/update";
        }*/

        //监听添加
        form.on('submit(putIn)', function(data){
            layer.alert("恭喜你，操作成功！",{
                title: 'crm提示'
            })
            //向后台发送ajax请求
            $.ajax({
                //编写json格式，设置属性和值
                url:"http://localhost:8080/crm/customerOrder/save",
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify(data.field),
                dataType:"json",
                type:"post",
                async:false,
                success:function (data){
                    //服务器端成功响应的json数据，进行解析
                },
                //刷新页面
                end:parent.location.reload(),
            })
            return false;
        });

    });

</script>
</body>
</html>